package com.tally.framework.security.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;

import com.tally.project.system.user.domain.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

public class LoginUser implements UserDetails {
	/** 用户名 */
    private String username;
    /** 用户名 */
    private String password;
	/** 登陆时间戳（毫秒） */
	private Long loginTime;
	/** 过期时间戳（小于等于0则不过期） */
	private Long expireTime;
    /** 用户信息 */
	private User user;

    public LoginUser() {
    }

    public LoginUser(String username, User user) {
        this.user = user;
        this.username = username;
        this.password = user.getPassword();
    }

    @Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return null;
	}

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    /** 账户是否未过期 */
	@JsonIgnore
	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	/** 账户是否未锁定 */
	@JsonIgnore
	@Override
	public boolean isAccountNonLocked() {
//		return user.getStatus() != Constants.LOCKED;
		return true;
	}

	/** 密码是否未过期 */
	@JsonIgnore
	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	/** 账户是否激活 */
	@JsonIgnore
	@Override
	public boolean isEnabled() {
		return true;
	}

	public Long getLoginTime() {
		return loginTime;
	}

	public void setLoginTime(Long loginTime) {
		this.loginTime = loginTime;
	}

	public Long getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(Long expireTime) {
		this.expireTime = expireTime;
	}

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public int hashCode() {
        return username.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return this.toString().equals(obj.toString());
    }

}
